-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(a32nx/fcu): Fixed FCU ALT selector immediately switching to 1000s when interval selected #9784
base: master
Are you sure you want to change the base?
Conversation
Thank you for the contribution 🙌 |
First of all, thank you for your contribution! Unfortunately, this C++ code is autogenerated from a Simulink model, and so cannot be edited directly unfortunately. I will however glady add your changes to the model and regenerated the code. Out of interest, do you know what happens when the FCU initializes? Does it round to the selected increment, or always 100/1000? |
Ah okay, it did look a little complicated in that area. From memory, when the FCU initialises, it's always 100ft regardless of which interval is selected. |
Hey, I have integrated the changes into the simulink model according to your specifications (with a few changes to optimize branching and code readability (well, in the simulink model/matlab code, the generated code is still not very readable, sorry)), and listed you as co-author. I hope that was OK for you. Sorry that your original changes could not be taken over 1to1 in the generated code |
function value = fcn(in)
knob_turns = in.data.discrete_inputs.afs_inputs.alt_knob.turns;
% Compute the increment float value from the boolean discrete input
increment = single(100 + in.data.discrete_inputs.afs_inputs.alt_increment_1000 * 900);
% Init the target to the current value, and round to the appropriate
% increment.
persistent pValue;
if isempty(pValue)
pValue = round(in.logic.afs.chosen_fmgc_data.alt_ft / increment) * increment;
end
% If the sim value sync input is not -1, set the value to the input.
if in.data.sim_input.alt ~= -1
pValue = in.data.sim_input.alt;
end
% Increment or decrement the target according to current selected
% increment. Only round once the value is changed, not if the increment was
% changed. (increment / 2 + 1) is implemented to prevent possibly skipping
% a thousands after switching from 100s to 1000s increment.
if in.data.sim_input.alt ~= -1 || knob_turns ~= 0
pValue = round((pValue + single(knob_turns) * (increment / 2 + 1)) / increment) * increment;
end
% Limit target to max and min values.
pValue = max(min(pValue, 49000), 100);
value = pValue; This is the original code in the matlab function block, in case you're interested |
No worries Luke, Looks good! |
Fixes #9699
Summary of Changes
Updated FcuComputer.cpp so that it doesn't run the code if number of turns of the ALT knob are 0 (which is the case where the increment knob is turned). Also had to add logic so that if the currently selected altitude is in hundreds (interval=1000ft), when the ALT knob is moved it doesn't jump by more than 1000ft - e.g. the code would have gone from 6300ft straight to 5000ft when dialling the altitude down with the previous version of the code as round(6300ft - 1000ft) = 5000ft - but we just want 6300ft to go to 6000ft on the first turn of the knob.
Screenshots (if necessary)
References
Behaviour observed on IRL aircraft
Additional context
First time contributing to an opensource project - so I hope I've followed the process right, but I was software engineer at Thales before my 320 TR flying for about 5 years now so hopefully I can contribute a little more going forward.
Discord username (if different from GitHub):
Testing instructions
Select an altitude in 100s of feet. Change the interval selector to 1000s of feet. Note the selected altitude doesn't change, it remains in 100s of feet.
Select an altitude with 100s of feet between 100 and 400ft. Change the interval selector to 1000s of feet. Turn the ALT selector knob to increase altitude, observe it increases the altitude to the next thousand. Repeat, but turn the ALT selector knob to decrease altitude, observe the altitude is just rounded down.
Select an altitude with 100s of feet between 600 and 900ft. Change the interval selector to 1000s of feet. Turn the ALT selector knob to increase altitude, observe it increases the altitude to the next thousand. Repeat, but turn the ALT selector knob to decrease altitude, observe the altitude is rounded down.
Select an altitude with 100s of feet with 500ft (e.g. 1500ft). Change the interval selector to 1000s of feet. Turn the ALT selector knob to increase altitude, observe it increases the altitude to the next thousand. Repeat, but turn the ALT selector knob to decrease altitude, observe the altitude is rounded down.
General testing of other altitude selection behaviour, also check that the minimum selection of 100ft and maximum of 49000ft has been unaffected.
How to download the PR for QA
Every new commit to this PR will cause new A32NX and A380X artifacts to be created, built, and uploaded.